IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spILPData_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spILPData_RetrieveAll'
		DROP  Procedure  spILPData_RetrieveAll
	END

GO

PRINT 'Creating Procedure spILPData_RetrieveAll'
GO

CREATE Procedure spILPData_RetrieveAll
	(
		@ID int = null, 
		@AccNo varchar(13) = null, 
		@BondAmt money = null, 
		@OutBal money = null, 
		@AmtPastDue money = null, 
		@ValAmt money = null, 
		@PrePaid money = null, 
		@Monthly money = null, 
		@BondRegDate DateTime = null, 
		@ValDate DateTime = null, 
		@Status char(3) = null, 
		@SubStatus char(3) = null, 
		@BranchCode char(3) = null, 
		@custID varchar(25) = null, 
		@custName1 varchar(100) = null, 
		@custName2 varchar(100) = null, 
		@custPersTel varchar(20) = null, 
		@custBussTel varchar(20) = null, 
		@custContTel varchar(20) = null, 
		@AccountDate DateTime = null, 
		@Suburb varchar(50) = null, 
		@Stand varchar(50) = null, 
		@Complex varchar(50) = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 8/22/2007	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	ILPData
	
	WHERE	(@ID IS NULL OR ILPData.ID = @ID)
	  AND	(@AccNo IS NULL OR ILPData.AccNo LIKE @AccNo + '%')
	  AND	(@BondAmt IS NULL OR ILPData.BondAmt = @BondAmt)
	  AND	(@OutBal IS NULL OR ILPData.OutBal = @OutBal)
	  AND	(@AmtPastDue IS NULL OR ILPData.AmtPastDue = @AmtPastDue)
	  AND	(@ValAmt IS NULL OR ILPData.ValAmt = @ValAmt)
	  AND	(@PrePaid IS NULL OR ILPData.PrePaid = @PrePaid)
	  AND	(@Monthly IS NULL OR ILPData.Monthly = @Monthly)
	  AND	(@BondRegDate IS NULL OR ILPData.BondRegDate = @BondRegDate)
	  AND	(@ValDate IS NULL OR ILPData.ValDate = @ValDate)
	  AND	(@Status IS NULL OR ILPData.Status = @Status)
	  AND	(@SubStatus IS NULL OR ILPData.SubStatus = @SubStatus)
	  AND	(@BranchCode IS NULL OR ILPData.BranchCode = @BranchCode)
	  AND	(@custID IS NULL OR ILPData.custID LIKE @custID + '%')
	  AND	(@custName1 IS NULL OR ILPData.custName1 LIKE @custName1 + '%')
	  AND	(@custName2 IS NULL OR ILPData.custName2 LIKE @custName2 + '%')
	  AND	(@custPersTel IS NULL OR ILPData.custPersTel LIKE @custPersTel + '%')
	  AND	(@custBussTel IS NULL OR ILPData.custBussTel LIKE @custBussTel + '%')
	  AND	(@custContTel IS NULL OR ILPData.custContTel LIKE @custContTel + '%')
	  AND	(@AccountDate IS NULL OR ILPData.AccountDate = @AccountDate)
	  AND	(@Suburb IS NULL OR ILPData.Suburb LIKE @Suburb + '%')
	  AND	(@Stand IS NULL OR ILPData.Stand LIKE @Stand + '%')
	  AND	(@Complex IS NULL OR ILPData.Complex LIKE @Complex + '%')

	-- Return to calling method
	RETURN
GO
